﻿<%@ Page Title="" Language="C#" MasterPageFile="~/Master.Master" AutoEventWireup="true"
    CodeBehind="Index.aspx.cs" Inherits="MsgCenter.Web.Pages.DeptManage.Index" %>

<asp:Content ID="Content1" ContentPlaceHolderID="headerContent" runat="server">
    <link rel="stylesheet" media="screen" type="text/css" href="<%=ResolveClientUrl("~/JavaScript/Tree/tree.css") %>" />
    <script type="text/javascript" src="<%=ResolveClientUrl("~/JavaScript/Tree/tree.js") %>"></script>
    <script type="text/javascript" src="<%=ResolveClientUrl("~/JavaScript/FirePlat/assets/js/jqGrid/myJqgrid.js") %>"></script>
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="mainContent" runat="server">
    <div class="page-content">
        <div class="row">
            <div class="col-xs-12">
                <div class="row">
                    <div class="col-sm-6">
                        <div class="widget-box">
                            <div class="widget-header header-color-blue2">
                                <h4 class="lighter smaller">
                                    部门列表</h4>
                            </div>
                            <div class="widget-body">
                                <div class="widget-main padding-8">
                                    <div id="tree" style="height: 420px; overflow-x: no; overflow-y: auto;">
                                        <img src="../../Images/tree/loading.gif" />
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>
                    <%--<div class="col-sm-6">
                        <div class="widget-box">
                            <div class="widget-header header-color-green2">
                                <h4 class="lighter smaller">
                                    操作功能</h4>
                            </div>
                            <div class="widget-body">
                                <div class="widget-main padding-8">
                                    <span>所选名称:</span><input type="text" id="txtDeptName" />
                                </div>
                                <div class="widget-main padding-8" id="divAuth">
                                </div>
                            </div>
                        </div>
                    </div>--%>
                </div>
            </div>
        </div>
    </div>
    <input type="hidden" id="hidDeptID" />
    <script type="text/javascript">
        function GetModelAuth() {
            $.get("../../Handlers/Handler_UserAuth.ashx?method=GetAuthOperateMax", { ModuleID: "<%=strRequestID %>" },
                    function (txt) {
                        $("#divAuth").html(txt);
                    }
                );
        }
        function CreateTree() {
            var o = {
                cbiconpath: "../../Images/tree/",
                emptyiconpath: "../../Images/tree/s.gif",
                showcheck: false,
                onnodeclick: function (item) {
                    document.getElementById("txtDeptName").value = setStr(item.text);
                    document.getElementById("hidDeptID").value = item.value;
                }
            };
            $.ajax({
                type: "GET",
                url: "../../Handlers/Handler_Dept.ashx?method=GetDeptTree",
                success: function (msg) {
                    eval("var data =" + msg + ";");
                    o.data = data;
                    $("#tree").treeview(o);
                },
                error: function (msg) {
                    alert("获取数据出现错误:" + msg);
                }
            });
        }
        function RestLoad() {
            $("#tree").html("<img src='../../Images/tree/loading.gif' />");
            LoadTree();
        }

        function LoadTree() {
            window.setTimeout(CreateTree, 100);
        }

        $(document).ready(function () {
            //GetModelAuth();
            LoadTree();
        });

        function AlertMessageBoxSelect(file_name) {
            if (file_name == "Refresh") {
                return;
            }
        }

        function setStr(str) {
            return str;
        }

        function Add() {
            var Url = 'Option.aspx?type=Add&DeptGuID=' + $("#hidDeptID").val();
            ShowWindow("部门管理", Url);
        }

        function Edit() {
            if ($("#hidDeptID").val() == "00000000-0000-0000-0000-000000000000") {
                showDialogMessage("该节点不能进行修改或删除");
                return false;
            }
            if ($("#hidDeptID").val() == "") {
                showDialogMessage("请先选择节点再进行操作");
                return false;
            }
            var Url = 'Option.aspx?type=Edit&DeptGuID=' + $("#hidDeptID").val();
            ShowWindow("部门管理", Url);
        }

        function Delete() {
            if ($("#hidDeptID").val() == "00000000-0000-0000-0000-000000000000") {
                showDialogMessage("该节点不能进行修改或删除");
                return;
            }
            if ($("#hidDeptID").val() == "") {
                showDialogMessage("请先选择节点再进行操作");
                return;
            }
            var varDeptID = $("#hidDeptID").val();
            $.get("../../Handlers/Handler_Dept.ashx?method=GetChildrenCount", { DeptID: varDeptID, random: Math.random() },
                    function (txt) {
                        if (txt == "0") {
                            ShowConfirm(varDeptID);
                        }
                        else {
                            showDialogMessage("选择删除的部门节点含有下级部门,不能进行删除");
                            return false;
                        }
                    }
                );
        }

        function Sort() {
            if ($("#hidDeptID").val() == "") {
                showDialogMessage("请先选择节点再进行操作");
                return false;
            }
            var Url = 'Option.aspx?type=Sort&DeptGuID=' + $("#hidDeptID").val();
            ShowWindow("部门管理", Url);
        }
        function ShowWindow(varTitle, varUrl) {
            var o = {
                title: varTitle,
                href: varUrl
            };
            showColorbox(o);
            return false;

        }

        function ShowConfirm(modelID) {
            var o = {
                DeleteURL: "../../Handlers/Handler_Dept.ashx?method=Delete&DeptID=" + modelID,
                ReLoad: RestLoad
            };
            showConfirmDialog(o);
        }

        function CBClose() {
            $.colorbox.close();
        }

        function CBClose_Load() {
            $.colorbox.close();
            showDialogMessage("操作数据成功");
            RestLoad();
        }
        
    </script>
</asp:Content>
